<?php

namespace app\admin\model;

use think\Model;

/**
 * 社群分类
 * @package app\admin\model
 */
class ResourceCate extends Model
{
    /**
     * 获取社群分类
     * @param $where
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function getResourceCate($where = [])
    {
        $data = self::where($where)->where([
            ['pid', '<>', 0],
            ['status', '=', 1]
        ])->select();
        return $data ? $data->toArray() : [];
    }

    /**
     * 社群分类值
     * @param $where
     * @return mixed
     */
    public static function findResourceCateValue($where)
    {
        return self::where($where)->value('name');
    }

    /**
     * 社群分类颜色
     * @return array
     */
    public static function getResourceColor()
    {
        return self::where([
            ['pid', '<>', 0],
            ['status', '=', 1]
        ])->column('color');
    }

    /**
     * 更新社群分类
     * @param $data
     * @param $where
     * @return ResourceCate
     */
    public static function updateResourceCate($data, $where)
    {
        return self::update($data, $where);
    }

}